import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);
const store = new Vuex.Store({
        state: {
            user: {
                info: {
                    name: "init",
                    role: null,
                    avatar: null
                },
                isLogin: false
            },
            posting: {
                content: null,
                title: null
            }
        },
        getters: {
            userName: state => state.user.info.name,
            userRole: state => state.user.info.role,
            isLogin: state => state.user.isLogin,
            postingContent: state => state.posting.content,
            postingTitle: state => state.posting.title,
        },
        mutations: {
            setUserName: (state, name) => state.user.info.name = name,
            setAvatar: (state, avatar) => state.user.info.avatar = avatar,
            setUserRole: (state, role) => state.user.info.role = role,
            resetPosting: (state) => {
                state.posting.content = null;
                state.posting.title = null;
            }
        },
        actions: {}
    })
;
export default store;